
/**
** \file       input.c
**
** \brief      this function parse the input rule
**
** \author     Ben M'rad Hanna, Laterem Hamza, Boillot Ulysse,
**             De Olivera Guillaume and Nguyen Viet Dung
**
** \version    1.0
**
** \date       28 Novembre 2010
**
*/

#include "rules.h"

s_ast             *rule_input(s_ast     *ast)
{
  if (g_data->lexer == NULL)
    return (NULL);

  if (((strcmp(g_data->lexer->token->id, "EOF") == 0)
       || (strcmp(g_data->lexer->token->id, "\n") == 0)
       || (strcmp(g_data->lexer->token->id, "\0") == 0))
      && ((g_data->lexer->next == NULL)
          || strcmp(g_data->lexer->next->token->id, "\n") == 0))
    return (ast);

  ast->list = calloc(1, sizeof (s_list));

  if ((rule_list(ast->list) != NULL) && (g_data->lexer != NULL)
      && ((strcmp(g_data->lexer->token->id, "EOF") == 0)
          || (strcmp(g_data->lexer->token->id, "\n") == 0)
          || (strcmp(g_data->lexer->token->id, "\0") == 0))
      && ((g_data->lexer->next == NULL)
          || strcmp(g_data->lexer->token->id, "\n") == 0))
    return (ast);

  free(ast->list);
  ast->list = NULL;

  return (NULL);
}
